package com.ibeeking.found.common.config.feign.fallback;

import com.ibeeking.found.common.config.feign.GoodsCommonClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class GoodsCommonClientFallbackFactory implements FallbackFactory<GoodsCommonClient> {
    @Override
    public GoodsCommonClient create(Throwable throwable) {
        return new GoodsCommonClient() {
            @Override
            public ResponseResult<Boolean> createJobInfoForGoodsUsageSurvey(Integer tenantId) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，任务初始化失败。" + throwable.getMessage(), false);
            }

            @Override
            public ResponseResult<Boolean> delJobInfoForGoodsUsageSurvey(Integer tenantId) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，任务删除失败。" + throwable.getMessage(), false);
            }
        };
    }
}
